
def func(file_path, new_value):
    # 读取原始文件内容
    with open(file_path, 'r') as file:
        lines = file.readlines()

    # 修改指定的行
    with open(file_path, 'w') as file:
        for line in lines:
            # 去除空格读取字符以nc开头
            if line.strip().startswith('nc:'):
                file.write(f'nc: {new_value}\n')
            else:
                file.write(line)

def main():
    file_path = r'D:\yolov5s.yaml'
    new_nc_value = 6
    func(file_path, new_nc_value)

if __name__ == "__main__":
    main()
